package com.bootcamp.s3_1013.database.utils;

import com.bootcamp.s3_1013.database._1019_JBUtils.City;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

/**
 * @program: myClassCode
 * @description: my own result set handler
 * @author: Keyu Li
 * @create: 2021-10-19 20:33
 **/

public class MyBeanListResultSetHandler implements ResultSetHandler {

    @Override
    public Object handle(ResultSet resultSet) throws SQLException {
        List<City> cities = new LinkedList<>();
        while (resultSet.next()) {
            City city = new City();
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            int pid = resultSet.getInt("pid");
            city.setId(id);
            city.setName(name);
            city.setPid(pid);
            cities.add(city);
        }
        return cities;
    }
}
